package com.hxl.aop.controller;

import com.hxl.aop.entity.Apple;
import com.hxl.aop.entity.Orange;
import com.hxl.aop.res.AjaxResult;
import com.hxl.aop.service.Fruit;
import com.hxl.aop.service.LoveService;
import com.hxl.aop.utils.SpringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Aop测试控制层
 *
 * @author 霍帅帅
 * @since 2024-06-11 23:30
 */
@RestController
@RequestMapping("/aop")
public class AopTestController {

    private static final Logger log = LoggerFactory.getLogger(AopTestController.class);

    @Autowired
    private Fruit apple;

    @Autowired
    private Fruit orange;

    @Autowired
    private LoveService loveService;

    @GetMapping("/say")
    public AjaxResult sayLove() {
        System.out.println("开始说: ");
        System.out.println("loveService: " + loveService.getClass().getName());
        return AjaxResult.success(loveService.sayLove());
    }

    @GetMapping("/eat")
    public AjaxResult eatFruit() {
        System.out.println("开始吃: ");
        Fruit apple1 = SpringUtil.getBean(Apple.class);
        Fruit orange1 = SpringUtil.getBean(Orange.class);

        System.out.println("apple: " + apple1.getClass().getName());
        apple1.eat();
        System.out.println("orange: " + orange1.getClass().getName());
        orange1.eat();
        return AjaxResult.success("没有啦");
    }

    @GetMapping("/eat2")
    public AjaxResult eatFruit2() {
        System.out.println("开始吃: ");
        System.out.println("apple: " + apple.getClass().getName());
        apple.eat();
        System.out.println("orange: " + orange.getClass().getName());
        orange.eat();
        return AjaxResult.success("没有啦");
    }

    @GetMapping("/logback")
    public AjaxResult testLogBack(){
        log.debug("debug日志示例");
        log.info("info日志示例");
        log.warn("warn日志示例");
        log.error("error日志示例");
        return AjaxResult.success("###logback测试###");
    }
}
